import esriLoader from 'esri-loader'

var initDraw = function (mapId,type,DrawEndFunction) {
  esriLoader.loadModules(["widget/Draw","widget/MapManager"])
    .then(([Draw,MapManager]) => {
      var map = MapManager.getMap(mapId);
      var draw = Draw.getInstance(map);
      Draw.setActivate(type);
      if(DrawEndFunction && typeof DrawEndFunction == "function"){
        Draw.setDrawEnd(function (evt) {
          DrawEndFunction(evt);
        },function () {
          Draw.deactivate();
        });
      }
    })
    .catch(err => {
      // handle any script or module loading errors
      console.error(err);
    })
}
export default {
  initDraw
}
